/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kalc.deuxdee;

import kalc.deuxdee.DeuxDee;
import java.util.Iterator;

/**
 *
 * @author martin
 */
public class Scale2d implements DeuxDee{
  private final DeuxDee _from;
  private final int _scaleW,
                    _scaleH;
  
  public Scale2d(final DeuxDee from, final int scaleW, final int scaleH){
    _from=from;
    _scaleW=scaleW;
    _scaleH=scaleH;
  }
  
  public static DeuxDee fromSquareSize(final DeuxDee from, int size){
    return new Scale2d(from, size, size);
  }
  
  public static DeuxDee fromRect(final DeuxDee from, int w, int h){
    return new Scale2d(from, w, h);
  }
  
  @Override
  public int h() {
    return _from.h()*_scaleW;
  }

  @Override
  public int index(int x, int y) {
    return _from.index(x/_scaleW, y/_scaleH);

  }

  @Override
  public int size() {
    return _from.size();
  }

  @Override
  public int w() {
    return _from.w()*_scaleH;
  }

  @Override
  public int x(int index) {
    return _from.x(index)*_scaleW;
  }

  @Override
  public int y(int index) {
    return _from.y(index)*_scaleH;
  }

  @Override
  public Iterator<Integer> iterator() {
    return _from.iterator();
  }
  
}
